package com.mofish.zbserver.common.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mofish.zbserver.common.CommonService;
import com.mofish.zbserver.common.Constants;
import com.mofish.zbserver.common.dao.CommonDao;
import com.mofish.zbserver.common.model.user.User;


@Service
@Transactional
public class CommonServiceImpl implements CommonService {

	@Resource
	private CommonDao commonDao;
	
	@Override
	public User getUserByU_id(String u_id) {
		User user = commonDao.getUserByU_id(u_id);
		user.setU_avatar(Constants.IMG_PATH_HOST + user.getU_avatar());
		return commonDao.getUserByU_id(u_id);
	}

	@Override
	public String getU_avatarByU_name(String u_name) {
		String u_avatar = commonDao.getU_avatarByU_name(u_name);
		u_avatar = Constants.IMG_PATH_HOST + u_avatar;
		
		return u_avatar;
	}

	@Override
	public String selectU_nameByU_id(String u_id) {
		String u_name = commonDao.selectU_nameByU_id(u_id);
		return u_name;
	}

	@Override
	public Integer selectUserCountByU_name(String u_name) {
		Integer cnt = commonDao.selectUserCountByU_name(u_name);
		return cnt;
	}

	/**
	 * 获取不带密码的User对象
	 */
	@Override
	public User getUserWithoutU_pwdByU_id(String u_id) {
		User user = commonDao.getUserByU_id(u_id);
		user.setU_avatar(Constants.IMG_PATH_HOST + user.getU_avatar());
		user.setU_pwd(null);
		return user;
	}
}
